//
//  ChatModel.swift
//  AESOLAR_IOS
//
//  Created by Mr.Wang on 2019/8/29.
//  Copyright © 2019 Mr.Wang. All rights reserved.
//

import HandyJSON

struct ChatListModel: HandyJSON {
    var total = 0
    var list: [ChatModel] = []
}

struct ChatModel: HandyJSON {

    var createTime = ""
    var content = ""
    var type: ChatModelType = .my
    var ossList: [ChatImageModel] = []
    
    static func createWith(content: String) -> ChatModel {
        var model = ChatModel()
        model.content = content
        model.type = .my
        let dateFormate = DateFormatter()
        dateFormate.dateFormat = "yyyy-MM-dd HH:mm:ss"
        model.createTime = dateFormate.string(from: Date())
        return model
    }
    
    static func createWith(image: UIImage, id: String) -> ChatModel {
        SDImageCache.shared.store(image, forKey: APPConfig.imagePath + id, completion: nil)
        var model = ChatModel()
        model.ossList = [ChatImageModel(id: id)]
        model.type = .my
        let dateFormate = DateFormatter()
        dateFormate.dateFormat = "yyyy-MM-dd HH:mm:ss"
        model.createTime = dateFormate.string(from: Date())
        return model
    }
}

struct ChatImageModel: HandyJSON {
    var id: String = ""
}

enum ChatModelType: String, HandyJSONEnum {
    case my = "0"
    case other = "1"
}
